-- localization
-- Created by chengb Oct/10/2015
-- 本地化支持

-- 根据语言版本加载不同的文件
local loc_table = nil;
local default_loc_table = nil;

function initCoreLang()
    local lang = UserDefaultM.getStringForKey("APP_LANG");
    if lang == "zh" then
        loc_table  = require "core/loc/loc_zh";
    elseif lang == "tw" then
        loc_table  = require "core/loc/loc_tw";
    elseif lang == "th" then
        loc_table = require "core/loc/loc_th";
    elseif lang == "ja" then
        loc_table = require "core/loc/loc_ja";
    elseif lang == "pt" then
        loc_table = require "core/loc/loc_pt";
    elseif lang == "fr" then
        loc_table = require "core/loc/loc_fr";
    elseif lang == "es" then
        loc_table = require "core/loc/loc_es";
    elseif lang == "ru" then
        loc_table = require "core/loc/loc_ru";
    elseif lang == "de" then
        loc_table = require "core/loc/loc_de";
    elseif lang == "ko" then
        loc_table = require "core/loc/loc_ko";
    else
        loc_table  = require "core/loc/loc_en";
    end

    default_loc_table = require "core/loc/loc_en";
end

function getCoreLocStr(key)
    if loc_table[key] == nil then
        if default_loc_table[key] == nil then
            return key;
        else
            return default_loc_table[key];
        end
    end

    return loc_table[key];
end

-- 获取需要下载的语言包
function getLangPkg(lang)
    if lang == nil or lang == "" then
        return nil;
    end

    local langPkgList = { tw = "lang_tw", th = "lang_th", ja = "lang_ja", pt = "lang_pt", fr = "lang_fr", es = "lang_es", ru = "lang_ru", de = "lang_de", ko = "lang_ko", };
    return langPkgList[lang];
end

function getCoreLocFontName(lang)
    if lang == "zh" then
        return "fonts/simhei.ttf";
    elseif lang == "tw" then
        return "fonts/simhei.ttf";
    elseif lang == "ja" then
        return "fonts/simhei.ttf";
    elseif lang == "th" then
        return "fonts/cordia.ttf";
    else
        return "fonts/impact.ttf";
    end
end

initCoreLang();